package leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class LeetCodeMain59 {
    public int findLength(int[] nums1, int[] nums2) {
        int length1=nums1.length;
        int length2=nums2.length;
        int[][] dp=new int[length1+1][length2+1];
        int max=0;
        dp[0][0]=0;
        for (int i = 1; i <= length1; i++) {
            for (int j = 1; j <= length2; j++) {
                if (nums1[i-1]==nums2[j-1]){
                    dp[i][j]=dp[i-1][j-1]+1;
                }
                if (max<dp[i][j]){
                    max=dp[i][j];
                }
            }
        }
        return max;
    }
    public int findLengthOfLCIS(int[] nums) {
        if (nums.length == 1) {
            return 1;
        }
        int length = nums.length;
        int[] dp = new int[length];
        Arrays.fill(dp, 1);
        int max = 1;
        for (int i = 0; i < length-1; i++) {
            if (nums[i]<nums[i+1]){
                dp[i+1]=dp[i]+1;
            }
            if (max<dp[i+1]){
                max=dp[i+1];
            }
        }
        return max;
    }
    public int lengthOfLIS(int[] nums) {
        if (nums.length==1){
            return 1;
        }
        int length=nums.length;
        int[] dp=new int[length];
        Arrays.fill(dp,1);
        int max=0;
        for (int i = 1; i <length; i++) {
            for (int j = 0; j < i; j++) {
                if (nums[i]>nums[j]){
                    dp[i]=Math.max(dp[i],dp[j]+1);
                }
            }
            if (dp[i]>max){
                max=dp[i];
            }
        }
        return max;
    }
    public static void main2(String[] args) {
        Scanner in=new Scanner(System.in);
        String minString=in.nextLine();
        String maxString=in.nextLine();
        if (minString.length()>maxString.length()){
            String string=minString;
            minString=maxString;
            maxString=string;
        }
        int length=0;
        for (int i = 0; i < minString.length(); i++) {
            for (int j = i+1; j <= minString.length(); j++) {
                String st=minString.substring(i,j);
                if (maxString.contains(st)&&j-i>length){
                    length=j-i;
                }
            }
        }
        System.out.println(length);
    }
    public static void main1(String[] args) {
        Scanner in=new Scanner(System.in);
        String string=in.nextLine();
        StringBuffer buffer=new StringBuffer();
        buffer.append(string);
        buffer.reverse();
        System.out.println(buffer.toString());
    }
}
